package com.yunlongn.httpclient.factory;

import com.yunlongn.httpclient.annotation.HttpServer;
import org.springframework.core.annotation.AliasFor;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.annotation.MergedAnnotation;
import org.springframework.core.annotation.MergedAnnotations;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Optional;

public class HttpServerHandler implements InvocationHandler {
    private Class<?> apiClass;



    public HttpServerHandler(Class<?> apiClass, String host){
        this.apiClass = apiClass;
        HttpServer httpServer = apiClass.getAnnotation(HttpServer.class);
        if (httpServer == null) {
            throw new NullPointerException("not find @HttpServer BY " + apiClass.getName());
        }
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        HttpServer httpServer = apiClass.getAnnotation(HttpServer.class);
        MergedAnnotations mergedAnnotations = MergedAnnotations.from(method);
        MergedAnnotation<?> mergedAnnotation = mergedAnnotations.get(RequestMapping.class);
        Optional<RequestMethod[]> requestMethods = mergedAnnotation.getValue("method", RequestMethod[].class);

        return null;
    }
}
